<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
include 'obj_app.php';
$connection1 = mysql_connect("1.234.53.52", "cam", "5678" ) ;
mysql_select_db("testbk130108", $connection1);
mysql_query("set names 'utf8'");
$id_employee='1323404319486';
$_SESSION['user']='dklien';
$_SESSION['bklist']=array();
$sql="SELECT a.*,e.FullName	FROM approvedoc a,employee e WHERE a.IDEmployee=e.IDEmployee  and a.IDLabel<1 AND a.IDEmployee='$id_employee' AND a.IDStatus=1 ";
$query= mysql_query($sql." ORDER BY a.Timecreate desc");
$sl=mysql_num_rows($query);
if($sl>0){
	while($row=mysql_fetch_array($query)){
		$obj= new appobj();
		$obj->newapprovedoc($row['FullName'], $row['IDApproveDoc'], $row['Tile'], $row['Content'], $row['IDEmployee'], $row['IDGroupApprove'], $row['SumMoney'], $row['Timecreate'], $row['IDStatus'], $row['IDTypeDoc'], $row['TimeApprove'], $row['comment'], $row['Description'], $row['purpose'], $row['Location'], $row['TripDate'], $row['TotalTime'], $row['EmployeePerforment'], $row['Content2'], $row['isView'], $row['IDLabel']);
		$_SESSION['bklist'][$row['IDApproveDoc']]=$obj;
	}
}

mysql_close($connection1);
$sl=count($_SESSION['bklist']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script src="jquery-1.8.2.js" type="text/javascript"></script>

<script>
</script>
<script>
var sd;
window.onload = function(){
	loadbackup();
};
function backup(){
	var listid="";
	$("input[name='chon']").each(function(){
		if (this.checked) listid = listid+","+this.value;
    	})
    
	listid=listid.substr(1);
	if(listid!=""){
		hoi= confirm("sure?");
		if (hoi==true) {
			$.ajax({url:"aj_backup.php",data:{lchk:listid},success:function(rsbk){
				$("#idfilebk").html(rsbk);
				$.ajax({url:"aj_loadbkcontent.php",success:function(rslbk1){
					$("#showlist").html(rslbk1);
				}});
			}});
		}
    }
}
function loadbackup(){
	$.ajax({url:"aj_loadbackup.php",success:function(rslbk4){
		$("#idfilebk").html(rslbk4);
	}});
}

function clickdownload(tenfile){
	window.location="aj_downloadbk.php?tenfile="+encodeURI(tenfile);
}

function clickChonHetRoi(ele){
	var status=ele.checked;
	$("input[name='chon']").each(function(){this.checked=status;})
}

function clickrestore(){
	$.ajax({url:"aj_restorecontent.php",success:function(rslbk3){
		$("#showlistrestore").html(rslbk3);
	}});
}

function restore(tenfile){
	$.ajax({url:"aj_prorestore.php",data:{tenfile:tenfile},success:function(rslbk2){
		$("#showlist").html(rslbk2);
		clickrestore();
		loadbackup();
	}});
}

function onecheck(ten){
	var gt=document.getElementById("chon"+ten).checked;
	document.getElementById("chon"+ten).checked = !gt;
}


var dong=0;
$(document).bind('keydown',function(evt) {
	//var key = window.event ? e.keyCode : e.which;	
    switch(evt.keyCode) {
                case 38:
          //evt.preventDefault();
          if(dong>0){
			dong = dong -1;
			alert(dong);
          }
                break;
            }
});

$(document).bind('keydown',function(evt) {
	//var key = window.event ? e.keyCode : e.which;	
    switch(evt.keyCode) {
                case 40:
          //evt.preventDefault();
          if(dong>0){
			dong = dong + 1;
			alert(dong);
          }
                break;
            }
});
</script>
</head>
<body style="height:100%" >
<form id="fn" name="fn" method="post" action="" >
<div style="width:100%">
    <div style="padding-right:20px;">
    	<p id="idfilebk">
	    	
    	</p>
    	<input style="font-size: 12px;" type="button" onclick="backup()" name="bkbackup" value="Backup" class="btnupbg btnupload" />
    	<input style="font-size: 12px;" type="button" onclick="clickrestore()" name="bkrestore" value="Restore" class="btnupbg btnupload" />
    </div>
    <div id="showlistrestore">
    </div>
    <div id="showlist" style="width:100%">
    	<table border="1" style="width:100%">
    		<tr>
    			<td width="3%"><input type="checkbox" name="chonhetroi" id="chonhetroi" onclick="clickChonHetRoi(this);"/></td>
				<td width="3%">No.</td>
	            <td width="15%">Type</td>
	            <td width="30%">Title</a></td>
	            <td width="10%">Time created</a></td>
	            <td width="10%">Time approved</a></td>
    		</tr>
    	<?php 
    		if($sl>0){
    			$ob= new appobj();
    			$i=0;
    			foreach ($_SESSION['bklist'] as $k=>$gt){
    				$ob=unserialize (serialize ($gt));
    				?>
    				<tr bgcolor="#ffffff" id="<?php echo "idtr".$i; ?>" class="highlighter" onclick="onecheck(<?=$i?>)" style="cursor: pointer;" >
						<td><input type="checkbox" onclick="onecheck(<?=$i?>)" id="<?php echo "chon".$i; ?>" name="chon" value="<?=$ob->idapprovedoc?>" /></td>
						<td width="3%" align="center"><?=(++$i)?></td>
						<td ><div  align="left" ><?=$ob->idtypedoc?></div></td>
						<td >
							<?=$ob->title?>							
						</td>
						<td ><?=$ob->timecreat?></td>
						<td ><?=$ob->timeapprove?></td>
						
					</tr>
    				<?php 
    			}
    		}
    	?>
    	</table>
    </div>
</div>
</form>
</body>
</html>